package com.example.controller;

import com.example.common.Result;
import com.example.entity.Order;
import com.example.entity.Order_Product;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.example.service.OrderService;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;


    @PostMapping("/create")
    public Result createOrder(@RequestBody Order order) {

        orderService.createOrder(order);
        return Result.success();
    }

    @GetMapping("/selectPageByBusinessAndStatus")
    public Result selectPageByBusiness_status(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "6") Integer pageSize, Integer id,Integer status) {
        PageInfo<Order_Product> pageInfo = orderService.selectPageByBusiness_status(currentPage, pageSize, id,status);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectPageByUserAndStatus")
    public Result selectPageByUser_status(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "6") Integer pageSize, Integer id,Integer status) {
        PageInfo<Order_Product> pageInfo = orderService.selectPageByUser_status(currentPage, pageSize, id,status);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectPageByuser")
    public Result selectPageByUser(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "6") Integer pageSize, Integer id) {
        PageInfo<Order_Product> pageInfo = orderService.selectPageByUser(currentPage, pageSize, id);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectPageByBusiness")
    public Result selectPageByBusiness(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "6") Integer pageSize, Integer id) {
        PageInfo<Order_Product> pageInfo = orderService.selectPageByBusiness(currentPage, pageSize, id);
        return Result.success(pageInfo);
    }

    @GetMapping("selectByNo/{orderNo}")
    public Result selectById(@PathVariable String orderNo) {
        Order order = orderService.selectByNo(orderNo);
        return Result.success(order);
    }

    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody Order order) {
        orderService.updateStatus(order);
        return Result.success();
    }

    @PostMapping("/updatePayTime")
    public Result updatePayTime(@RequestBody Order order) {
        orderService.updatePayTime(order);
        return Result.success();
    }

    @PostMapping("/updateEndTime")
    public Result updateEndTime(@RequestBody Order order) {
        orderService.updateEndTime(order);
        return Result.success();
    }

}
